unit clsRegistroExportacao;

interface

uses dm,dbtables,biblio;

type
  TRegistroExportacao=Class(TObject)
    public
      Reg_AnoMes  : string;
      Reg_Despacho: string;
      Reg_Moeda   : string;
      Reg_Pais    : string;
      function  Recuperar(Reg_Numero: String): Boolean;
      procedure Gravar(Reg_Numero: String);
      procedure Excluir(Reg_Numero: String);
      procedure Consultar(var tq: TQuery);
  end;

implementation


procedure TRegistroExportacao.Gravar;
var tq: TQuery;
begin
 tq             := Tquery.Create(DmInt);
 tq.databasename:= dmint.Db.DatabaseName;
 tq.active      := False;
 tq.sql.clear;
 tq.params.clear;
 tq.sql.add('Select * from RegistroExportacao where Reg_Numero=:a');
 tq.params[0].asstring:= Reg_Numero;
 tq.open;
 if tq.eof then begin
  tq.close;
  tq.sql.clear;
  tq.params.clear;
  tq.sql.add('Insert into RegistroExportacao values('+
             ':k_Reg_Numero  ,'+
             ':k_Reg_AnoMes  ,'+
             ':k_Reg_Despacho,'+
             ':k_Reg_Moeda   ,'+
             ':k_Reg_Pais    )');
 end else begin
  tq.close;
  tq.sql.clear;
  tq.params.clear;
  tq.sql.add('Update RegistroExportacao set '+
             'Reg_AnoMes  =:k_Reg_AnoMes   ,'+
             'Reg_Despacho=:k_Reg_Despacho ,'+
             'Reg_Moeda   =:k_Reg_Moeda    ,'+
             'Reg_Pais    =:k_Reg_Pais      '+
             'where Reg_Numero=:k_Reg_Numero');
 end;
 tq.parambyname('k_Reg_Numero').asstring  := Reg_Numero;
 tq.parambyname('k_Reg_AnoMes').asstring  := Reg_AnoMes;
 tq.parambyname('k_Reg_Despacho').asstring:= Reg_Despacho;
 tq.parambyname('k_Reg_Moeda').asstring   := Reg_Moeda;
 tq.parambyname('k_Reg_Pais').asstring    := Reg_Pais;
 tq.execsql;
 tq.close;
 tq.free;
end;

function TRegistroExportacao.Recuperar;
var tq: TQuery;
begin
 tq             := Tquery.Create(dmint);
 tq.databasename:= DmInt.Db.DatabaseName;
 tq.active      := False;
 tq.sql.clear;
 tq.params.clear;
 tq.sql.add('Select * from RegistroExportacao where Reg_Numero=:a');
 tq.params[0].asstring:= Reg_Numero;
 tq.open;
 Reg_AnoMes  := tq.fieldbyname('Reg_AnoMes').asstring;
 Reg_Despacho:= tq.fieldbyname('Reg_Despacho').asstring;
 Reg_Moeda   := tq.fieldbyname('Reg_Moeda').asstring;
 Reg_Pais    := tq.fieldbyname('Reg_Pais').asstring;
 result      := not tq.eof;
 tq.close;
 tq.free;
end;

procedure TRegistroExportacao.Excluir;
var tq: TQuery;
begin
 tq             := Tquery.Create(dmint);
 tq.databasename:= dmint.db.databasename;
 tq.active      := false;
 tq.sql.Clear;
 tq.params.clear;
 tq.sql.add('Delete from RegistroExportacao where Reg_Numero=:a');
 tq.params[0].asstring:= Reg_Numero;
 tq.execsql;
 tq.close;
 tq.free;
end;

procedure TRegistroExportacao.Consultar;
begin
 tq.close;
 tq.sql.Clear;
 tq.params.Clear;
 tq.sql.add('Select * from RegistroExportacao');
 tq.open;
end;

end.

